/**
* SwaggerConfig.java
* Created at 2018年7月25日
* Created by 胡锐锋
* Copyright (C) 2018 SAIC VOLKSWAGEN, All rights reserved.
*/
package com.lits.file.config;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

	@Bean
	public Docket createRestApi() {
		return new Docket(DocumentationType.SWAGGER_2).globalOperationParameters(getCommonHeaders()).apiInfo(apiInfo())
				.select().apis(RequestHandlerSelectors.basePackage("com.lits.file.controller"))
				.paths(PathSelectors.any()).build();
	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder().title("File-Svc").description("").termsOfServiceUrl("").version("0.0.1").build();
	}

	/**
	 * 获取公共请求头信息
	 */
	protected List<Parameter> getCommonHeaders() {
		ParameterBuilder headerParamBuilder = new ParameterBuilder();
		headerParamBuilder.name("Authorization").description("认证头").modelRef(new ModelRef("string"))
				.parameterType("header").defaultValue("").required(false).build();
		List<Parameter> pars = new ArrayList<>();
		pars.add(headerParamBuilder.build());
		return pars;
	}

}
